package com.vsd.repository;

import java.util.Collection;
import java.util.Date;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RestResource;

import com.vsd.domain.User;

/**
 * 用户User CrudRepository定义
 * 
 * @author jiekechoo
 *
 */
@RestResource(exported = false)
public interface UserRepository extends CrudRepository<User, String> {

	Collection<User> findAll();

	User findByUsername(String username);

	Page<User> findAll(Pageable p);

	Page<User> findByUsernameContaining(String searchPhrase, Pageable p);
	
	Page<User> findByPhone(String phone, Pageable p);
	
	User findByPasswordAndUsername(String password,String username);
	
	@Query("SELECT count(*) FROM User u WHERE u.username = ?1")
	int countByUserName(String account);
	
	@Query("SELECT count(1) FROM User u WHERE u.createTime >= ?1")
	int countByCreateTime(Date time);

}
